﻿
@{
    ViewBag.Title = "订单详细";
}

@model OrderRecordDTO[]
<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote permission_search">
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后未提交的数据不会自动保存</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold"> @Model.Count() </span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form permission_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <td>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </td>
                            <td>订单编号</td>
                            <td>商品名称</td>
                            <td>价格</td>
                            <td>数量</td>
                            <td>商品评论</td>
                            <td>查看详细评论</td>
                            <td>评论等级</td>
                            <td>包装类型</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody class="orderRecord_content">
                        @foreach (var orderRecord in Model)
                        {
                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                        <i class="layui-icon"></i>
                                    </div>
                                </td>
                                <td>@orderRecord.OrderGuid</td>
                                <td>@orderRecord.GoodName</td>
                                <td>@orderRecord.Price</td>
                                <td>@orderRecord.Count</td>
                                @if (orderRecord.Comment != null)
                                {
                                    <td>@(orderRecord.Comment.Length > 10 ? orderRecord.Comment.Substring(0, 11) + "..." : orderRecord.Comment)</td>
                                }
                                else
                                {
                                    <td>还未评论</td>
                                }

                                    <td>
                                        @if (@orderRecord.CommentId != null)
                                        {
                                            <a class="layui-btn layui-btn-mini orderRecord_comment" data-id="@orderRecord.CommentId">
                                                <i class="iconfont icon-edit"></i>
                                                查看详细评论
                                            </a>
                                        }
                                        else
                                        {
                                            <a class="layui-btn layui-btn-mini">
                                                <i class="iconfont icon-edit"></i>
                                                还未评论
                                            </a>
                                        }

                                    </td>
                                <td>

                                    @if (orderRecord.Level <= 0)
                                    {
                                        @("尚未评价")
                                    }
                                    else
                                    {
                                        for (int i = 0; i < orderRecord.Level; i++)
                                        {
                                            <i class="layui-icon" style="color: #e20000;">&#xe600;</i>
                                        }
                                    }


                                </td>
                                <td>@orderRecord.PackName</td>
                                <td>
                                    <a class="layui-btn layui-btn-mini orderRecord_edit" data-id="@orderRecord.Id">
                                        <i class="iconfont icon-edit"></i>
                                        编辑
                                    </a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini orderRecord_del" data-id="@orderRecord.Id">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>

        </div>
    </div>

</section>


@section FooterScript{
    <script type="text/javascript">
        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery'], function () {
            var form = layui.form(),
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                $ = layui.jquery;

            //操作
            $("body").on("click", "." + appConfig.name + "_comment", function () {  //编辑
                var index = layui.layer.open({
                    title: "查看评论",
                    type: 2,
                    area: ['100%', '800px'],   //弹出层的宽高
                    content: "/Comment/Edit?commentId=" + $(this).attr("data-id"),
                    success: function (layero, index) {
                        setTimeout(function () {
                            layui.layer.tips('点击此处返回' + appConfig.title + '列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        }, 500)
                    }
                })
                layui.layer.full(index);
            })
        });

        var $;

        var appConfig = {
            name: "orderRecord",    @*需要和页面名称对应*@
            title: "订单详细记录",    @*显示的名称*@
            addUrl: "",   @*添加弹框的路径*@

            @*修改弹框的路径 这里不用写出具体id（和后台controller里的对应就行）的值，js会自动获取并拼成链接
            后台获取id是通过data-id="1" 属性获取的 ，所以需要在编辑上也加上 data-id="@@orderRecord.Id"*@
            editUrl: "/OrderRecord/Edit?id=",
            $: "",
            layer: "",
            area: ['100%', '600px'],   //弹出层的宽高

            del: function (data) {
                $ = appConfig.$

                $.ajax({
                    url: "/orderRecord/Delete/",
                    method: "post",
                    dataType: "json",
                    data: { "orderRecordId": data },
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", { icon: 1 });

                        } else {
                            appConfig.layer.msg("删除失败", { icon: 5 });
                        }
                    },
                    error: function () {
                        appConfig.layer.msg("删除失败", { icon: 5 });
                    }
                });

                //todo:在此处添加删除记录的ajax
            }
        };



    </script>
}
